package org.kernely.test.stream;

import org.kernely.test.testbundle.TestBundle;
import org.kernely.ui.mvp.KernelyPresenter;

import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;

/**
 * Presenter to test streams.
 */
public class StreamsPresenter extends KernelyPresenter<StreamsView>{

	/**
	 * @see org.kenely.ui.mvp.IKernelyPresenter#bind()
	 */
	@Override
	public void bind() {
		this.view.getNewStreamButton().addListener(new Button.ClickListener() {
			
			/**
			 * Action when the button is clicked.
			 */
			public void buttonClick(ClickEvent event) {
				// Get the content entered by the user
				String content = view.getContentField().getValue().toString();
				
				// Post on the stream
				TestBundle.getStreamService().postOnBundleStream(TestBundle.TEST_STREAM_ID, "Posted from user interface", content);
				
				// Change the focus and remove the text
				view.getContentField().focus();
				view.getContentField().setValue("");
			}
		});
	}

}
